package com.sugou.dao.support.ext.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.sugou.dao.enums.ConditionsType;
import com.sugou.dao.support.Statement;
import com.sugou.dao.support.ext.Conditions;

public class ParentConditionsImpl extends ArrayList<Conditions> implements Conditions,List<Conditions> {
	private static final long serialVersionUID = -1451054657649970093L;

	
	private ConditionsType type;
	
	public ParentConditionsImpl(List<Conditions> body,ConditionsType type) {
		super(body);
		this.type=type;
	}

	public List<Serializable> getParams() {
		List<Serializable> list=new ArrayList<Serializable>();
		for (Conditions cdt : this) {
			list.addAll(cdt.getParams());
		}
		return this.getParams();
	}

	public String getContent() {
		StringBuilder str=new StringBuilder("(");
		boolean first=true;
		for (Conditions cdt : this) {
			if(first){
				first=false;
			}else{
				str.append(cdt.getType().name().toLowerCase()).append(" ");
				str.append(cdt.getBody().getContent()).append(" ");
			}
		}
		str.append(")");
		return str.toString();
	}
	
	public Statement getBody() {
		return this;
	}

	public ConditionsType getType() {
		return type;
	}

}
